package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/15 14:30
 */
public class LS_Offer_47 {
    public int maxValue(int[][] grid) {
        int l = grid.length;
        int h = grid[0].length;
        for (int i = 0; i < l; i++) {
            for (int j = 0; j < h; j++) {
                if (i==0 && j==0) {
                    continue;
                }
                if (i==0 && j!=0) {
                    grid[i][j]+=grid[i][j-1];
                }
                if (i!=0 && j==0) {
                    grid[i][j]+=grid[i-1][j];
                }
                if (i!=0&&j!=0) {
                    grid[i][j]= grid[i][j] + Math.max(grid[i-1][j],grid[i][j-1]);
                }

            }
        }
        return grid[l-1][h-1];

    }
}
